package ce.com.cenewbluesdk.proxy;

import android.content.Context;
import android.os.Message;
import android.util.Log;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import ce.com.cenewbluesdk.CEBC;
import ce.com.cenewbluesdk.bluetooth.CEBlueTooth_4;
import ce.com.cenewbluesdk.connect.ReconnectModeA;
import ce.com.cenewbluesdk.entity.CEDevData;
import ce.com.cenewbluesdk.entity.k6.K6_Action;
import ce.com.cenewbluesdk.entity.k6.K6_CESyncTime;
import ce.com.cenewbluesdk.entity.k6.K6_DevInfoStruct;
import ce.com.cenewbluesdk.entity.k6.K6_HeartStruct;
import ce.com.cenewbluesdk.entity.k6.K6_MessageNoticeStruct;
import ce.com.cenewbluesdk.entity.k6.K6_MixInfoStruct;
import ce.com.cenewbluesdk.entity.k6.K6_MusicInfo;
import ce.com.cenewbluesdk.entity.k6.K6_OTAStateInfo;
import ce.com.cenewbluesdk.entity.k6.K6_SendAlarmInfoStruct;
import ce.com.cenewbluesdk.entity.k6.K6_SendDevSettingStruct;
import ce.com.cenewbluesdk.entity.k6.K6_SendGoal;
import ce.com.cenewbluesdk.entity.k6.K6_SendUserInfo;
import ce.com.cenewbluesdk.entity.k6.K6_SendWeatherStruct;
import ce.com.cenewbluesdk.entity.k6.K6_Send_Watch_Face_And_Notification_Set;
import ce.com.cenewbluesdk.entity.k6.K6_Sport;
import ce.com.cenewbluesdk.ota.ota_modea.OtaK6Control;
import ce.com.cenewbluesdk.queue.CEProtocolB;
import ce.com.cenewbluesdk.uitl.ByteUtil;
import ce.com.cenewbluesdk.uitl.CRC16;
import ce.com.cenewbluesdk.uitl.Lg;

/**
 * Created by Administrator on 2016/12/20 0020.
 */

public class CEDevK6Proxy extends CEBluetoothProxyBase {

    public static final String UUID = "0000cc66-0000-1000-8000-00805f9b34fb";
//    public static final String UUID = "6E400001-B5A3-F393-E0A9-77656C6F6F70";

    public static final int devType = 6;

    SendHelper sendHelper = new SendHelper();

    private String devVersion;

    private OtaK6Control otaControl;

    public SendHelper getSendHelper() {
        return sendHelper;
    }

    protected CEDevK6Proxy(Context context) {
        super(context);
    }

    @Override
    protected void dataSendSucceed(CEDevData devData) {
//        switch (devData.getDataType()) {
//            case CEBC.K6.DATA_TYPE_OTA_DATA:
//                otaControl.otaDataSendResult(1);
//                break;
//            case CEBC.K6.DATA_TYPE_GPS_ARGUMENT:
//                sendMeg(createMessage(CEBC.K6.DATA_TYPE_GPS_ARGUMENT, 1));
//                break;
//
//        }
        sendResult(devData,K6_Action.SEND_R.DATA_SEND_SUCCESS);

    }

    @Override
    protected void DataSendFailed(CEDevData devData) {
//        switch (devData.getDataType()) {
//            case CEBC.K6.DATA_TYPE_OTA_DATA:
////                otaControl.otaDataSendResult(0);
//                break;
//            case CEBC.K6.DATA_TYPE_GPS_ARGUMENT:
//                sendMeg(createMessage(CEBC.K6.DATA_TYPE_GPS_ARGUMENT, 0));
//                break;
//        }

        sendResult(devData,K6_Action.SEND_R.DATA_SEND_FAIL);
    }

    @Override
    protected void receiptData(CEDevData devData) {
        analysisCEDevData(devData);

    }

    @Override
    protected void blueToothConnectStateChange(int state) {
        lge("连接状态发送改变："+state);
        sendMeg(createMessage(CEBC.BLUE_CONNECT_STATE_CHANGE, state));
        if (state == CEBC.BLUE_CONNECTED) {
        }
    }

    @Override
    protected void initProxy() {
        blueTooth = new CEBlueTooth_4(context, UUID);
        connectUtil = new CEConnectUtil(context, new ReconnectModeA(), this, blueTooth);
        devQueue = new CEDevQueue(this, new CEProtocolB(devType), blueTooth);
        otaControl = new OtaK6Control(this, context);

    }

    @Override
    protected String getClassName() {
        return "CEDevK6Proxy";
    }


    public void startOta() {
        otaControl.startOta("2.0.2.0.0", devVersion, "");
    }

    public class SendHelper {
        public void sendUserInfo(K6_SendUserInfo userInfo) {
            devQueue.push(userInfo.toCEDevData());
        }

        public void sendTime() {
            K6_CESyncTime time = K6_CESyncTime.getCurrentTime();
            devQueue.push(time.toCEDevData());
        }

        public void sendSetting(K6_SendDevSettingStruct settingStruct) {
            devQueue.push(settingStruct.toCEDevData());
        }

        public void getDevInfo() {
            CEDevData data = new CEDevData();
            data.setCmd(CEBC.K6.CMD_TYPE_REQUEST);
            data.setDataType(CEBC.K6.DATA_TYPE_DEVINFO);
            devQueue.push(data);
        }


        /**
         * 获取混合数据
         */
        public void getMixInfo() {
            CEDevData data = new CEDevData();
            data.setCmd(CEBC.K6.CMD_TYPE_REQUEST);
            data.setDataType(CEBC.K6.DATA_TYPE_DEV_SYNC);
            devQueue.push(data);
        }


        /**
         * 发送闹钟设置信息
         */
        public void sendAlarmInfo(
                ArrayList<K6_SendAlarmInfoStruct> alarm_Info_Structs) {
//            if (alarm_Info_Structs == null || alarm_Info_Structs.size() == 0)
//                return;
            byte[] payload = new byte[K6_SendAlarmInfoStruct.getItemSize() * alarm_Info_Structs.size() + 1];
            lge("发送闹钟设置信息,共" + alarm_Info_Structs.size() + "组闹钟");
            payload[0] = (byte) alarm_Info_Structs.size();
            for (int i = 0; i < alarm_Info_Structs.size(); ++i) {
                K6_SendAlarmInfoStruct this_alrm = alarm_Info_Structs.get(i);
                byte[] this_alarm_payload = this_alrm.getBytes();
                System.arraycopy(this_alarm_payload, 0, payload, i * K6_SendAlarmInfoStruct.getItemSize() + 1, K6_SendAlarmInfoStruct.getItemSize());
            }
            lge("发送闹钟设置信息,payload : " + Arrays.toString(payload));
            CEDevData data = new CEDevData();
            data.setCmd(CEBC.K6.CMD_TYPE_SEND);
            data.setDataType(CEBC.K6.DATA_TYPE_ALARM);
            data.setItemL(payload.length);
            data.setData(payload);
            data.setItemNumber(1);
            devQueue.push(data);
        }


        /**
         * 短信通知信息
         */
        public void sendMessage_notice(
                long time, String name, String content, byte messageType) {
            if (name == null || content == null) {
                return;
            }
            Log.e("liu", "短信发送给设备侧了  。");
            K6_MessageNoticeStruct msg = new K6_MessageNoticeStruct(time, messageType);
            msg.setSendContext(name, K6_MessageNoticeStruct.Property.TYPE_CONTENT, content);

            sendMessage_notice(msg);
        }


        public void sendMessage_notice(K6_MessageNoticeStruct msg) {
            devQueue.push(msg.toCEDevData());
        }

        /**
         * 发送天气信息
         *
         * @param weatherStruct
         */
        public void sendWeatherInfo(K6_SendWeatherStruct weatherStruct) {
            devQueue.push(weatherStruct.toCEDevData());
        }


        /**
         * 设置目标
         */
        public void sendGoal(K6_SendGoal enable) {

            devQueue.push(enable.toCEDevData());
        }

        /**
         * 发送音乐信息
         */
        public void sendMusicInfo(K6_MusicInfo enable) {

            devQueue.push(enable.toCEDevData());
        }


        /**
         * 设置gesensor数据传输开关
         */
        public void setEnableGsDataTrans(boolean enable) {
            CEDevData data = new CEDevData(CEBC.K6.CMD_TYPE_SEND, CEBC.K6.DATA_TYPE_SET_DATA_SWITCH);
            data.setData(new byte[]{(byte) (enable ? 1 : 0)});
            devQueue.push(data);
        }


        /**
         * 发送混杂数据
         *
         * @param mixinfo
         */
        public void sendMixInfo(K6_MixInfoStruct mixinfo) {
            byte[] payload = mixinfo.getBytes();
            CEDevData data = new CEDevData();
            data.setCmd(CEBC.K6.CMD_TYPE_SEND);
            data.setDataType(CEBC.K6.DATA_TYPE_APP_SYNC);
            data.setItemL(payload.length);
            data.setItemNumber(1);
            data.setData(payload);
            devQueue.push(mixinfo.toCEDevData());
        }


        /**
         * 发送表盘通知等设置
         */
        public void sendWatchFace(K6_Send_Watch_Face_And_Notification_Set set) {

            devQueue.push(set.toCEDevData());
        }

        /**
         * 发送配对
         */
        public void sendPairStart() {
            CEDevData data = new CEDevData(CEBC.K6.CMD_TYPE_SEND, CEBC.K6.DATA_TYPE_PAIR_START);
            devQueue.push(data);
        }

        /**
         * * ota升级
         * 发送OTA数据
         *
         * @param crc        整个文件的CRC item数  和item
         * @param otaFileLen 整个文件的长 包涵文件的头部
         * @param index      这个data 在这个 文件的byte数组中的位置
         * @param data       发送的数据
         */
        public void sendOTAData(int crc, int otaFileLen, int index, byte[] data) {

            lge(" ota  index=" + index);

            CEDevData cedata = new CEDevData(CEBC.K6.CMD_TYPE_SEND, CEBC.K6.DATA_TYPE_OTA_DATA);

            cedata.setItemNumber(1);
            cedata.setItemL(data.length + 10);
            byte[] argv = new byte[10];
            System.arraycopy(ByteUtil.int2bytes2(crc), 0, argv, 0, 2);
            System.arraycopy(ByteUtil.intToByte4(otaFileLen), 0, argv, 2, 4);
            System.arraycopy(ByteUtil.intToByte4(index), 0, argv, 6, 4);
            byte[] sendbyte = new byte[data.length + 10];

            System.arraycopy(argv, 0, sendbyte, 0, 10);
            System.arraycopy(data, 0, sendbyte, 10, data.length);
            cedata.setData(sendbyte);
            cedata.setPriority(CEBC.PRIORITY_LOW);
            devQueue.push(cedata);
        }

        /**
         * ota升级
         * 请求设备侧的OTA状态
         */
        public void getOTAState() {
            CEDevData data = new CEDevData(CEBC.K6.CMD_TYPE_REQUEST, CEBC.K6.DATA_TYPE_OTA_STATUS);
            devQueue.push(data);
        }


        /**
         * 发送分包
         *
         * @param arg 每一个分包
         */
        public void sendGpsArgument(byte[] arg){
            CEDevData ceDevData = new CEDevData();
            ceDevData.setCmd(CEBC.K6.CMD_TYPE_SEND);
            ceDevData.setData(arg);
            ceDevData.setDataCrc16(CRC16.crc16(arg));
            ceDevData.setDataType(CEBC.K6.DATA_TYPE_GPS_ARGUMENT);
            ceDevData.setItemL(arg.length);
            devQueue.push(ceDevData);
        }


    }

    private void sendResult(CEDevData ceDevData, int result) {


        Message message = null;
        switch (ceDevData.getDataType()) {

            case CEBC.K6.DATA_TYPE_USERINFO:
                message = createMessage(K6_Action.SEND_R.SEND_USER_INFO, result);
                break;
            case CEBC.K6.DATA_TYPE_TIME:
                message = createMessage(K6_Action.SEND_R.SEND_TIME, result);
                break;
            case CEBC.K6.DATA_TYPE_SETTING:
                message = createMessage(K6_Action.SEND_R.SEND_DEV_SET, result);
                break;

            case CEBC.K6.DATA_TYPE_ALARM:
                message = createMessage(K6_Action.SEND_R.SEND_ALARM, result);
                break;
            case CEBC.K6.DATA_TYPE_MESSAGE_NOTICE:
                message = createMessage(K6_Action.SEND_R.SEND_MESSAGE_NOTICE, result);
                break;
            case CEBC.K6.DATA_TYPE_WEATHER:
                message = createMessage(K6_Action.SEND_R.SEND_WEATHER_STRUCT, result);
                break;
            case CEBC.K6.DATA_TYPE_SET_TARGET:
                message = createMessage(K6_Action.SEND_R.SEND_DEV_GOAL, result);
                break;
            case CEBC.K6.DATA_TYPE_MUSIC_CONTENT:
                message = createMessage(K6_Action.SEND_R.SEND_MUSIC_INFO, result);
                break;
            case CEBC.K6.DATA_TYPE_APP_SYNC:
                message = createMessage(K6_Action.SEND_R.SEND_MIX_INFO, result);
                break;
            case CEBC.K6.DATA_TYPE_WATCHFACE_MENU_SELECT:
                message = createMessage(K6_Action.SEND_R.SEND_WATCH_FACE_AND_NOTIFICATION_SET, result);
                break;
            case CEBC.K6.DATA_TYPE_PAIR_START:
                message = createMessage(K6_Action.SEND_R.SEND_PAIR_START, result);
                break;
            case CEBC.K6.DATA_TYPE_OTA_DATA:
                message = createMessage(K6_Action.SEND_R.SEND_OTA_DATA, result);
                break;
            case CEBC.K6.DATA_TYPE_GPS_ARGUMENT:
                message = createMessage(K6_Action.SEND_R.SEND_GPS_ARGUMENT, result);
                break;
            case CEBC.K6.DATA_TYPE_SET_DATA_SWITCH:
                message = createMessage(K6_Action.SEND_R.SEND_SET_DATA_SWITCH, result);
                break;


        }
        if(message!=null){
            sendMeg(message);
        }

    }


    private void analysisCEDevData(CEDevData ceDevData) {
        byte[] payload = null;
        switch (ceDevData.getDataType()) {
            case CEBC.K6.DATA_TYPE_USER_CHANGE:
                lge("用户信息改变，设备给APP发送的数据：" + CEBC.byte2hex(ceDevData.getData()));
                sendMeg(createMessage(K6_Action.RCVD.RCVD_USERINFO_CHANGE, 0));
                break;
            case CEBC.K6.DATA_TYPE_BATTERY_INFO:
                dealRcvdBattery(ceDevData.getData());
                break;
            case CEBC.K6.DATA_TYPE_DEVINFO:
                dealDevInfo(ceDevData.getData());
                break;
            case CEBC.K6.DATA_TYPE_DEV_SYNC:
                payload = ceDevData.getData();
                if (payload != null && payload.length > 0) {
                    K6_MixInfoStruct result = K6_MixInfoStruct
                            .parse(payload);
                    for (K6_MixInfoStruct.Property property : result.getList()) {
                        switch (property.getDate_type()) {
                            case CEBC.K6.DATA_TYPE_ALARM://闹钟
                                dealGetAlram(property.getData());
                                lge("闹钟:" + Arrays.toString(property.getData()));
                                break;
                            case CEBC.K6.DATA_TYPE_SETTING://设备设置信息
                                dealGetSetting(property.getData());
                                lge("设备设置信息:" + Arrays.toString(property.getData()));
                                break;
                            case CEBC.K6.DATA_TYPE_DEVINFO://设备信息
                                dealDevInfo(property.getData());
                                lge("设备信息:" + Arrays.toString(property.getData()));
                                break;
                            case CEBC.K6.DATA_TYPE_BATTERY_INFO://电池电量信息
                                dealRcvdBattery(property.getData());
                                lge("电池电量信息:" + Arrays.toString(property.getData()));
                                break;
                            case CEBC.K6.DATA_TYPE_WATCHFACE_MENU_SELECT://16 表盘、通知开关、Workout 设置信息
                                dealWacthFace_Notification_workout(property.getData());
                                lge("表盘设置:" + CEBC.byte2hex(property.getData()));
                                break;
                            case CEBC.K6.DATA_TYPE_OTA_STATUS:
                                dealOtaInfo(property.getData());
                                lge("OTA 信息");
                                break;
                        }
                    }
                }
                break;
            case CEBC.K6.DATA_TYPE_HISTORY_SPORT:
            case CEBC.K6.DATA_TYPE_REAL_SPORT:
                dealSportData(ceDevData);
                break;
            case CEBC.K6.DATA_TYPE_SLEEP:
                dealSleep(ceDevData);
                break;
            case CEBC.K6.DATA_TYPE_REAL_HEART:
                lge("DATA_TYPE_REAL_HEART");
                dealHeart(ceDevData);
                break;
            case CEBC.K6.DATA_TYPE_HISTORY_HEART:
                lge("DATA_TYPE_HISTORY_HEART");
                dealHeart(ceDevData);
                break;
            case CEBC.K6.DATA_TYPE_FIND_PHONE:
                dealFindPhone(ceDevData);
                break;
            case CEBC.K6.DATA_TYPE_REAL_GPS:
                lge("DATA_TYPE_REAL_GPS");
                dealGPS(ceDevData);
                break;
            case CEBC.K6.DATA_TYPE_HISTORY_GPS:
                lge("DATA_TYPE_HISTORY_GPS");
                dealGPS(ceDevData);
                break;
            case CEBC.K6.DATA_TYPE_ALARM:
                lge("DATA_TYPE_ALARM");
                dealGetAlram(ceDevData.getData());
                break;
            case CEBC.K6.DATA_TYPE_PHOTOGRAPH:
                lge("拍照  DATA_TYPE_PHOTOGRAPH");
                dealTakePhotos(ceDevData.getData());
                break;
            case CEBC.K6.DATA_TYPE_MUSIC_CONTROL:
//                lge("音乐控制   DATA_TYPE_MUSIC_CONTROL  ： "+ceDevData.getData()[0]);
//                K6_MusicInfo k=new K6_MusicInfo(ceDevData.getData()[0],"冯胖子","方盘子在那个山沟沟","冯大忽悠转xxxxxooooooooxxoxox") ;
//                getSendHelper().sendMusicInfo(k);
                dealMusicControl(ceDevData.getData());
                break;
            case CEBC.K6.DATA_TYPE_OTA_STATUS:
                dealOtaInfo(ceDevData.getData());
                break;
            case CEBC.K6.DATA_TYPE_PAIR_FINISH:
                dealPairFinish() ;
                break;
        }
    }


    /**
     * 处理获取到的设备信息
     *
     * @param payload
     */
    private void dealDevInfo(byte[] payload) {
        if (payload != null && payload.length > 0) {
            byte[] devInfo = new byte[K6_DevInfoStruct.devInfoByteLen];
            System.arraycopy(payload, 0, devInfo, 0,
                    K6_DevInfoStruct.devInfoByteLen);
            K6_DevInfoStruct dev_Info_Struct = K6_DevInfoStruct
                    .parseDevInfo(devInfo);
            devVersion = dev_Info_Struct.getSoftwareVer();
            lge("设备信息" + dev_Info_Struct.toString());
            sendMeg(createMessage(K6_Action.RCVD.RCVD_DEVINFO, dev_Info_Struct));
        } else {
            lge("收到设备信息的命令但是数据不对");
        }

    }

    /**
     * 处理电池信息
     *
     * @param payload
     */
    private void dealRcvdBattery(byte[] payload) {

        if (payload != null && payload.length > 0)
            sendMeg(createMessage(K6_Action.RCVD.RCVD_BATTERY, payload[0]));
    }

    /**
     * 处理运动数据
     */
    private void dealSportData(CEDevData devData) {
        byte[] datas = devData.getData();
        int allItem = ByteUtil.byte2ToInt(new byte[]{datas[0], datas[1]});
        int item = datas[2];

        lge("运动数据条目：" + "allItem=" + allItem + "   item= " + item);

        int index = 3;

        if (item * K6_Sport.getItemSize() != datas.length - 3) {
            lge("运动数据长度和item数对不上" + (datas.length - 3) + "item ：" + item);
            return;
        }
        ArrayList<K6_Sport> sports = new ArrayList<>();
        for (int i = 0; i < item; i++) {
            byte[] sprotData = new byte[K6_Sport.getItemSize()];
            System.arraycopy(datas, index, sprotData, 0, K6_Sport.getItemSize());
            K6_Sport k6_sport = new K6_Sport(sprotData);
            lge("接收到运动数据:" + k6_sport.toString());
            sports.add(k6_sport);
            index += K6_Sport.getItemSize();
        }
        if (sports.size() > 0) {
            sendMeg(createMessage(K6_Action.RCVD.RCVD_SPORT_DATA, sports));
        }
    }
//    private static void deal

    private void dealSleep(CEDevData ceDevData) {

        byte[] datas = ceDevData.getData();
        int allItem = ByteUtil.byte2ToInt(new byte[]{datas[0], datas[1]});
        int item = datas[2];

        lge("睡眠数据条目：" + "allItem=" + allItem + "   item= " + item);
        int index = 3;
        for (int i = 0; i < item; i++) {
            lge("睡眠数据当前包的长度：" + datas[index]);
            index++;
            int sleepItem = datas[index];
            lge("睡眠数据当前包的条目数：" + datas[index]);
            index++;
            int startTime = ByteUtil.byte4ToInt(new byte[]{datas[index], datas[index + 1], datas[index + 2], datas[index + 3]});
            lge("睡眠开始时间：" + startTime);
            index = index + 4;
            for (int j = 0; j < sleepItem; j++) {
                lge("睡眠状态=" + datas[index] + " 睡眠持续时间：" + ByteUtil.byte2ToInt(new byte[]{datas[index + 1], datas[index + 1]}));
                index = index + 3;
            }
        }


    }


    private void dealHeart(CEDevData ceDevData) {
        lge("接收到了心率数据");

        byte[] payload = ceDevData.getData();
        if (payload != null && payload.length > 0) {
            ArrayList<K6_HeartStruct> list = K6_HeartStruct.parse(payload);
            if (list.size() > 0) {
                sendMeg(createMessage(K6_Action.RCVD.RCVD_HEART, list));
            }
        }
    }

    private void dealFindPhone(CEDevData ceDevData) {

        byte[] bytes = ceDevData.getData();
        if (bytes != null & bytes.length > 0) {
            createMessage(K6_Action.RCVD.RCVD_FIND_PHONE, bytes[0]);
            lge("接收到了找手机的命令：" + bytes[0]);
        }
    }

    private void dealGPS(CEDevData ceDevData) {
        lge("接收到了gps的数据");
    }

    /**
     * /16 表盘、通知开关、Workout 设置信息
     *
     * @param payload
     */
    private void dealWacthFace_Notification_workout(byte[] payload) {
        if (payload != null) {
            byte[] info = new byte[K6_Send_Watch_Face_And_Notification_Set.getItemSize()];
            System.arraycopy(payload, 0, info, 0,
                    K6_Send_Watch_Face_And_Notification_Set.getItemSize());
            K6_Send_Watch_Face_And_Notification_Set setting = new K6_Send_Watch_Face_And_Notification_Set(info);
            lge("表盘设置信息：" + setting.toString());
            sendMeg(createMessage(K6_Action.RCVD.RCVD_WATCH_FACE_AND_NOTIFICATION_SET, setting));
        }

    }

    /**
     * 处理获取到的闹钟信息
     *
     * @param payload
     */
    private void dealGetAlram(byte[] payload) {
        int num = payload[0];
        lge("闹钟信息 num=" + num);
        ArrayList<K6_SendAlarmInfoStruct> alarm_info_struct_k3s = new ArrayList<>();
        for (int i = 0; i < num; i++) {
            int alarmFirstIndex = i * 4 + 1;
            alarm_info_struct_k3s.add(new K6_SendAlarmInfoStruct(payload[alarmFirstIndex],
                    payload[alarmFirstIndex + 1], payload[alarmFirstIndex + 2], payload[alarmFirstIndex + 3]));
        }
        sendMeg(createMessage(K6_Action.RCVD.RCVD_ALARM, alarm_info_struct_k3s));
    }

    /**
     * 获取到拍照的命令
     *
     * @param payload
     */
    private void dealTakePhotos(byte[] payload) {

        sendMeg(createMessage(K6_Action.RCVD.RCVD_TAKE_PHOTOS, 0));
    }

    /**
     * 处理设备传过来的设置信息
     *
     * @param payload
     */
    private void dealGetSetting(byte[] payload) {
        if (payload != null) {
            byte[] devInfo = new byte[K6_SendDevSettingStruct.getItemSize()];
            System.arraycopy(payload, 0, devInfo, 0,
                    K6_SendDevSettingStruct.getItemSize());
            K6_SendDevSettingStruct setting = new K6_SendDevSettingStruct(devInfo);
            lge("设备设置信息" + setting.toString());
            sendMeg(createMessage(K6_Action.RCVD.RCVD_DEV_SET, setting));
        }
    }


    /**
     * 处理ota信息
     */
    public void dealOtaInfo(byte[] data) {
        K6_OTAStateInfo otaStateInfo = new K6_OTAStateInfo(data);
        sendMeg(createMessage(K6_Action.RCVD.RCVD_OTA_INFO, otaStateInfo));

//        otaControl.otaStateResult(otaStateInfo);

    }

    /**
     * 接收到了配对成功的命令，表示连接成功
     */
    public void dealPairFinish() {
        sendMeg(createMessage(K6_Action.RCVD.RCVD_PAIR_FINISH, 1));
        lge("接收到了配对的消息，表示连接成功");
    }

    /**
     * 处理音乐控制命令
     */
    public void dealMusicControl(byte[] data) {
        if (data != null && data.length > 0) {
            sendMeg(createMessage(K6_Action.RCVD.RCVD_MUSIC_CONTROL, data[0]));
        } else {
            lge("接收到的音乐控制命令错误");
        }

    }


    public static void lge(String log) {
        Lg.e("k6", log);
    }

}
